home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / src / dmake / Localized-Source / convert.c < prev    next >
C/C++ Source or Header  |  1993-01-10  |  2KB  |  116 lines

  1. /*
  2. **    This file generated by localize 2.9 (AmigaDOS 2.1) from convert.c
  3. */
  4.  
  5. /*
  6.  *  CONVERT.C
  7.  */
  8.  
  9. #include "defs.h"
  10.  
  11. #define MAXLEVELS   10
  12.  
  13. Prototype int  WildConvert(char *, char *, char *, char *);
  14.  
  15. /*
  16.  *  Run srcBuf through the srcMat pattern matcher and if it matches
  17.  *  convert it via dstMat into dstBuf, else dstBuf \0 len.
  18.  */
  19.  
  20.  
  21. int
  22. WildConvert(srcBuf, dstBuf, srcMat, dstMat)
  23. char *srcBuf;
  24. char *dstBuf;
  25. char *srcMat;
  26. char *dstMat;
  27. {
  28.     short r = 0;
  29.     long i;
  30.     static short Index;
  31.     static short SubLen[MAXLEVELS];
  32.     static char *SubStr[MAXLEVELS];
  33.  
  34.     if (Index == MAXLEVELS)
  35.     error(FATAL, get_string(MSG_0002,"maximum recursion reached in WildConvert"));
  36.  
  37.     db4printf(("WildConvert %-15s (%s -> %s)\n", srcBuf, srcMat, (dstMat) ? dstMat : "..."));
  38.  
  39.     /*
  40.      *    skip non-wildcards, srcBuf must match srcMat
  41.      */
  42.  
  43.     while (*srcMat && *srcMat != '*' && *srcMat != '?') {
  44.     if (*srcBuf != *srcMat)
  45.         return(-1);
  46.     ++srcBuf;
  47.     ++srcMat;
  48.     }
  49.  
  50.     switch(*srcMat) {
  51.     case '\0':                      /*  match end, terminating case */
  52.     if (*srcBuf)                /*  buf srcBuf not exhausted!   */
  53.         r = -1;
  54.     break;
  55.     case '?':                       /*  match 1 */
  56.     if (*srcBuf == 0)           /*  match failed against srcbuf  */
  57.         return(-1);
  58.     SubStr[Index] = srcBuf;
  59.     SubLen[Index] = 1;
  60.     ++Index;
  61.     r = WildConvert(srcBuf + 1, NULL, srcMat + 1, NULL);
  62.     --Index;
  63.     break;
  64.     case '*':                       /*  match any   */
  65.     /*
  66.      *  strangeness in loop is so \0 (nil string) is checked for,
  67.      *  it is perfectly valid for the remainder to be nil.
  68.      *
  69.      *  note: bug in NeXT's GCC -O/-O2, had to reorder r == -1 to
  70.      *  the right side of the &&
  71.      */
  72.  
  73.     r = -1;
  74.     for (i = 0; (i == 0 || srcBuf[i-1]) && r == -1; ++i) {
  75.         SubStr[Index] = srcBuf;
  76.         SubLen[Index] = i;
  77.         ++Index;
  78.         r = WildConvert(srcBuf + i, NULL, srcMat + 1, NULL);
  79.         --Index;
  80.     }
  81.     break;
  82.     }
  83.     if (r == 0 && dstMat) {
  84.     short k = 0;
  85.     short n;
  86.  
  87.     while (*dstMat) {
  88.         switch(*dstMat) {
  89.         case '%':
  90.         n = (dstMat[1] - '1');
  91.         case '*':
  92.         case '?':
  93.         if (*dstMat == '%')
  94.             ++dstMat;
  95.         else
  96.             n = k++;
  97.  
  98.         if (n >= 0 && n < MAXLEVELS) {
  99.             movmem(SubStr[n], dstBuf, SubLen[n]);
  100.             dstBuf += SubLen[n];
  101.         }
  102.         break;
  103.         default:
  104.         *dstBuf++ = *dstMat;
  105.         break;
  106.         }
  107.         ++dstMat;
  108.     }
  109.     *dstBuf = 0;
  110.     }
  111.     db4printf((" r = %d\n", r));
  112.     return(r);
  113. }
  114.  
  115.  
  116.